package Test;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import objects.Map;

/**
 * 
 * @author Emanuel Martins 5940, Ana Pontes 5950 || date 05/06/2014
 * 
 *         This class runs the algorithm on the designated file with the given
 *         coordinates.
 * 
 */

public class TestAStar
{

   private static int     widthMap  = 512;
   private static int     heightMap = 512;
   private static int[][] obstacle;
   private static int     xStart    = 192;
   private static int     yStart    = 48;
   private static int     xEnd      = 260;
   private static int     yEnd      = 508;

   /**
    * This is the main method opens the file, makes a buffer to read it, and
    * makes a new map based on the file.
    * 
    */

   public static void main(String[] args)
   {
      String file = "resources/peppersgrad.pgm";
      String line;
      BufferedReader br;
      int counter = 0;
      Map mapa = null;
      int col = 0, row = 0;
      try
      {
         br = new BufferedReader(new FileReader(file));
         while ((line = br.readLine()) != null)
         {
            if (row >= heightMap - 1)
               break;
            if (counter == 2)
            {
               String[] WH = line.split(" ");
               mapa = new Map(Integer.parseInt(WH[0]), Integer.parseInt(WH[1]));
            }
            else if (counter == 3)
            {
               mapa.setMaxGray(Integer.parseInt(line));
            }
            else if (counter > 3)
            {
               if (col < mapa.getWidth())
               {
                  mapa.addNode(col, row, Integer.parseInt(line));
                  col++;
               }
               else
               {
                  col = 0;
                  row++;
                  mapa.addNode(col, row, Integer.parseInt(line));
               }
            }
            counter++;

         }
         br.close();

      } catch (FileNotFoundException e)
      {
         // TODO Auto-generated catch block
         e.printStackTrace();
      } catch (IOException e)
      {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }

   }

}